package com.ict.controller;

import com.ict.common.StateMsg;
import com.ict.model.*;
import com.ict.service.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by weiaquarius on 16/4/20.
 */
@Controller
@RequestMapping("/summary")
public class getCacheController {
    @Autowired
    public CacheService cacheService;

    /**
     * http://localhost:8080/alert/summary/getCache.do?insertTime=0&packageType=3&num=10
     * @param map
     * @param insertTime
     * @param packageType 1:Grids_Anomaly_Cache; 2:Inbound_Outbound_Cache; 3:Ships_Anomaly_Cache;
     *                    4:AIS_Device_Offline_Cache 5:Ship_Rendezvous_Cache
     * @param num 返回记录的数量
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getCache.do",method = RequestMethod.GET)
    public String getCache(ModelMap map, @RequestParam Double insertTime, @RequestParam Short packageType, @RequestParam Long num) {
        if (packageType == 1){
            List<GridsAnomalyCache> list = cacheService.getGridsAnomlyCache(insertTime,num);
            map.addAttribute("list",list);
        }
        else if (packageType == 2){
            List<InboundOutboundCache> list = cacheService.getInboundOutboundCache(insertTime,num);
            map.addAttribute("list",list);
        }
        else if (packageType == 3){
            List<ShipsAnomalyCache> list = cacheService.getShipsAnomlyCache(insertTime,num);
            map.addAttribute("list",list);
        }
        else if (packageType == 4){
            List<AISDeviceOfflineCache> list = cacheService.getAISDeviceOfflineCache(insertTime, num);
            map.addAttribute("list",list);
        }
        else if (packageType == 5){
            List<ShipRendezvousCache> list = cacheService.getShipRendezvousCache(insertTime, num);
            map.addAttribute("list",list);
        }
        return StateMsg.toJson(1, map);
    }

}
